/**
 *能发送异步ajax请求的函数模块
 * 封装axios库
 * 函数的返回值是promise对象
 */

import axios from 'axios';
import {message} from 'antd'

export default function ajax(url, data = {}, methodType = 'GET') {

    return new Promise((resolve, reject) => {
        let promise;
        // 1、执行异步Ajax请求
        if (methodType === 'GET') {
            promise = axios.get(url, {
                params: data
            });
        } else if (methodType === 'POST') {
            promise = axios.post(url, data);
        }
        // 2、请求成功
        promise.then(response => {
            resolve(response)
            // 3、请求失败
        }).catch(error => {
            message.error('请求出错了', error.message)
        })
    })
}

